home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / fortran / f2c-9510.000 / f2c-9510 / f2c-951007-libs-1.1 / src / exec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-07  |  19.4 KB  |  928 lines

  1. /****************************************************************
  2. Copyright 1990, 1993 - 1995 by AT&T Bell Laboratories and Bellcore.
  3.  
  4. Permission to use, copy, modify, and distribute this software
  5. and its documentation for any purpose and without fee is hereby
  6. granted, provided that the above copyright notice appear in all
  7. copies and that both that the copyright notice and this
  8. permission notice and warranty disclaimer appear in supporting
  9. documentation, and that the names of AT&T Bell Laboratories or
  10. Bellcore or any of their entities not be used in advertising or
  11. publicity pertaining to distribution of the software without
  12. specific, written prior permission.
  13.  
  14. AT&T and Bellcore disclaim all warranties with regard to this
  15. software, including all implied warranties of merchantability
  16. and fitness.  In no event shall AT&T or Bellcore be liable for
  17. any special, indirect or consequential damages or any damages
  18. whatsoever resulting from loss of use, data or profits, whether
  19. in an action of contract, negligence or other tortious action,
  20. arising out of or in connection with the use or performance of
  21. this software.
  22. ****************************************************************/
  23.  
  24. #include "defs.h"
  25. #include "p1defs.h"
  26. #include "names.h"
  27.  
  28. static void exar2 Argdcl((int, tagptr, struct Labelblock*, struct Labelblock*));
  29. static void popctl Argdcl((void));
  30. static void pushctl Argdcl((int));
  31.  
  32. /*   Logical IF codes
  33. */
  34.  
  35.  void
  36. #ifdef KR_headers
  37. exif(p)
  38.     expptr p;
  39. #else
  40. exif(expptr p)
  41. #endif
  42. {
  43.     pushctl(CTLIF);
  44.     putif(p, 0);    /* 0 => if, not elseif */
  45. }
  46.  
  47.  
  48.  void
  49. #ifdef KR_headers
  50. exelif(p)
  51.     expptr p;
  52. #else
  53. exelif(expptr p)
  54. #endif
  55. {
  56.     if (ctlstack->ctltype == CTLIF || ctlstack->ctltype == CTLIFX)
  57.     putif(p, 1);    /* 1 ==> elseif */
  58.     else
  59.     execerr("elseif out of place", CNULL);
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  void
  66. exelse(Void)
  67. {
  68.     register struct Ctlframe *c;
  69.  
  70.     for(c = ctlstack; c->ctltype == CTLIFX; --c);
  71.     if(c->ctltype == CTLIF) {
  72.         p1_else ();
  73.         c->ctltype = CTLELSE;
  74.         }
  75.     else
  76.         execerr("else out of place", CNULL);
  77.     }
  78.  
  79.  void
  80. #ifdef KR_headers
  81. exendif()
  82. #else
  83. exendif()
  84. #endif
  85. {
  86.     while(ctlstack->ctltype == CTLIFX) {
  87.         popctl();
  88.         p1else_end();
  89.         }
  90.     if(ctlstack->ctltype == CTLIF) {
  91.         popctl();
  92.         p1_endif ();
  93.         }
  94.     else if(ctlstack->ctltype == CTLELSE) {
  95.         popctl();
  96.         p1else_end ();
  97.         }
  98.     else
  99.         execerr("endif out of place", CNULL);
  100.     }
  101.  
  102.  
  103.  void
  104. #ifdef KR_headers
  105. new_endif()
  106. #else
  107. new_endif()
  108. #endif
  109. {
  110.     if (ctlstack->ctltype == CTLIF || ctlstack->ctltype == CTLIFX)
  111.         pushctl(CTLIFX);
  112.     else
  113.         err("new_endif bug");
  114.     }
  115.  
  116. /* pushctl -- Start a new control construct, initialize the labels (to
  117.    zero) */
  118.  
  119.  LOCAL void
  120. #ifdef KR_headers
  121. pushctl(code)
  122.     int code;
  123. #else
  124. pushctl(int code)
  125. #endif
  126. {
  127.     register int i;
  128.  
  129.     if(++ctlstack >= lastctl)
  130.         many("loops or if-then-elses", 'c', maxctl);
  131.     ctlstack->ctltype = code;
  132.     for(i = 0 ; i < 4 ; ++i)
  133.         ctlstack->ctlabels[i] = 0;
  134.     ctlstack->dowhile = 0;
  135.     ctlstack->domax = ctlstack->dostep = 0;    /* in case of errors */
  136.     ++blklevel;
  137. }
  138.  
  139.  
  140.  LOCAL void
  141. popctl(Void)
  142. {
  143.     if( ctlstack-- < ctls )
  144.         Fatal("control stack empty");
  145.     --blklevel;
  146. }
  147.  
  148.  
  149.  
  150. /* poplab -- update the flags in   labeltab   */
  151.  
  152.  LOCAL void
  153. poplab(Void)
  154. {
  155.     register struct Labelblock  *lp;
  156.  
  157.     for(lp = labeltab ; lp < highlabtab ; ++lp)
  158.         if(lp->labdefined)
  159.         {
  160.             /* mark all labels in inner blocks unreachable */
  161.             if(lp->blklevel > blklevel)
  162.                 lp->labinacc = YES;
  163.         }
  164.         else if(lp->blklevel > blklevel)
  165.         {
  166.             /* move all labels referred to in inner blocks out a level */
  167.             lp->blklevel = blklevel;
  168.         }
  169. }
  170.  
  171.  
  172. /*  BRANCHING CODE
  173. */
  174.  void
  175. #ifdef KR_headers
  176. exgoto(lab)
  177.     struct Labelblock *lab;
  178. #else
  179. exgoto(struct Labelblock *lab)
  180. #endif
  181. {
  182.     lab->labused = 1;
  183.     p1_goto (lab -> stateno);
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  void
  192. #ifdef KR_headers
  193. exequals(lp, rp)
  194.     register struct Primblock *lp;
  195.     register expptr rp;
  196. #else
  197. exequals(register struct Primblock *lp, register expptr rp)
  198. #endif
  199. {
  200.     if(lp->tag != TPRIM)
  201.     {
  202.         err("assignment to a non-variable");
  203.         frexpr((expptr)lp);
  204.         frexpr(rp);
  205.     }
  206.     else if(lp->namep->vclass!=CLVAR && lp->argsp)
  207.     {
  208.         if(parstate >= INEXEC)
  209.             errstr("statement function %.62s amid executables.",
  210.                 lp->namep->fvarname);
  211.         mkstfunct(lp, rp);
  212.     }
  213.     else if (lp->vtype == TYSUBR)
  214.         err("illegal use of subroutine name");
  215.     else
  216.     {
  217.         expptr new_lp, new_rp;
  218.  
  219.         if(parstate < INDATA)
  220.             enddcl();
  221.         new_lp = mklhs (lp, keepsubs);
  222.         new_rp = fixtype (rp);
  223.         puteq(new_lp, new_rp);
  224.     }
  225. }
  226.  
  227.  
  228.  
  229. /* Make Statement Function */
  230.  
  231. long laststfcn = -1, thisstno;
  232. int doing_stmtfcn;
  233.  
  234.  void
  235. #ifdef KR_headers
  236. mkstfunct(lp, rp)
  237.     struct Primblock *lp;
  238.     expptr rp;
  239. #else
  240. mkstfunct(struct Primblock *lp, expptr rp)
  241. #endif
  242. {
  243.     register struct Primblock *p;
  244.     register Namep np;
  245.     chainp args;
  246.  
  247.     laststfcn = thisstno;
  248.     np = lp->namep;
  249.     if(np->vclass == CLUNKNOWN)
  250.         np->vclass = CLPROC;
  251.     else
  252.     {
  253.         dclerr("redeclaration of statement function", np);
  254.         return;
  255.     }
  256.     np->vprocclass = PSTFUNCT;
  257.     np->vstg = STGSTFUNCT;
  258.  
  259. /* Set the type of the function */
  260.  
  261.     impldcl(np);
  262.     if (np->vtype == TYCHAR && !np->vleng)
  263.         err("character statement function with length (*)");
  264.     args = (lp->argsp ? lp->argsp->listp : CHNULL);
  265.     np->varxptr.vstfdesc = mkchain((char *)args, (chainp)rp);
  266.  
  267.     for(doing_stmtfcn = 1 ; args ; args = args->nextp)
  268.  
  269. /* It is an error for the formal parameters to have arguments or
  270.    subscripts */
  271.  
  272.         if( ((tagptr)(args->datap))->tag!=TPRIM ||
  273.             (p = (struct Primblock *)(args->datap) )->argsp ||
  274.             p->fcharp || p->lcharp ) {
  275.             err("non-variable argument in statement function definition");
  276.             args->datap = 0;
  277.             }
  278.         else
  279.         {
  280.  
  281. /* Replace the name on the left-hand side */
  282.  
  283.             args->datap = (char *)p->namep;
  284.             vardcl(p -> namep);
  285.             free((char *)p);
  286.         }
  287.     doing_stmtfcn = 0;
  288. }
  289.  
  290.  static void
  291. #ifdef KR_headers
  292. mixed_type(np)
  293.     Namep np;
  294. #else
  295. mixed_type(Namep np)
  296. #endif
  297. {
  298.     char buf[128];
  299.     sprintf(buf, "%s function %.90s invoked as subroutine",
  300.         ftn_types[np->vtype], np->fvarname);
  301.     warn(buf);
  302.     }
  303.  
  304.  void
  305. #ifdef KR_headers
  306. excall(name, args, nstars, labels)
  307.     Namep name;
  308.     struct Listblock *args;
  309.     int nstars;
  310.     struct Labelblock **labels;
  311. #else
  312. excall(Namep name, struct Listblock *args, int nstars, struct Labelblock **labels)
  313. #endif
  314. {
  315.     register expptr p;
  316.  
  317.     if (name->vtype != TYSUBR) {
  318.         if (name->vinfproc && !name->vcalled) {
  319.             name->vtype = TYSUBR;
  320.             frexpr(name->vleng);
  321.             name->vleng = 0;
  322.             }
  323.         else if (!name->vimpltype && name->vtype != TYUNKNOWN)
  324.             mixed_type(name);
  325.         else
  326.             settype(name, TYSUBR, (ftnint)0);
  327.         }
  328.     p = mkfunct( mkprim(name, args, CHNULL) );
  329.     if (p->tag == TERROR)
  330.         return;
  331.  
  332. /* Subroutines and their identifiers acquire the type INT */
  333.  
  334.     p->exprblock.vtype = p->exprblock.leftp->headblock.vtype = TYINT;
  335.  
  336. /* Handle the alternate return mechanism */
  337.  
  338.     if(nstars > 0)
  339.         putcmgo(putx(fixtype(p)), nstars, labels);
  340.     else
  341.         putexpr(p);
  342. }
  343.  
  344.  
  345.  void
  346. #ifdef KR_headers
  347. exstop(stop, p)
  348.     int stop;
  349.     register expptr p;
  350. #else
  351. exstop(int stop, register expptr p)
  352. #endif
  353. {
  354.     char *str;
  355.     int n;
  356.  
  357.     if(p)
  358.     {
  359.         if( ! ISCONST(p) )
  360.         {
  361.             execerr("pause/stop argument must be constant", CNULL);
  362.             frexpr(p);
  363.             p = mkstrcon(0, CNULL);
  364.         }
  365.         else if( ISINT(p->constblock.vtype) )
  366.         {
  367.             str = convic(p->constblock.Const.ci);
  368.             n = strlen(str);
  369.             if(n > 0)
  370.             {
  371.                 p->constblock.Const.ccp = copyn(n, str);
  372.                 p->constblock.Const.ccp1.blanks = 0;
  373.                 p->constblock.vtype = TYCHAR;
  374.                 p->constblock.vleng = (expptr) ICON(n);
  375.             }
  376.             else
  377.                 p = (expptr) mkstrcon(0, CNULL);
  378.         }
  379.         else if(p->constblock.vtype != TYCHAR)
  380.         {
  381.             execerr("pause/stop argument must be integer or string", CNULL);
  382.             p = (expptr) mkstrcon(0, CNULL);
  383.         }
  384.     }
  385.     else    p = (expptr) mkstrcon(0, CNULL);
  386.  
  387.     {
  388.     expptr subr_call;
  389.  
  390.     subr_call = call1(TYSUBR, (stop ? "s_stop" : "s_paus"), p);
  391.     putexpr( subr_call );
  392.     }
  393. }
  394.  
  395. /* DO LOOP CODE */
  396.  
  397. #define DOINIT    par[0]
  398. #define DOLIMIT    par[1]
  399. #define DOINCR    par[2]
  400.  
  401.  
  402. /* Macros for   ctlstack -> dostepsign   */
  403.  
  404. #define VARSTEP    0
  405. #define POSSTEP    1
  406. #define NEGSTEP    2
  407.  
  408.  
  409. /* exdo -- generate DO loop code.  In the case of a variable increment,
  410.    positive increment tests are placed above the body, negative increment
  411.    tests are placed below (see   enddo()   ) */
  412.  
  413.  void
  414. #ifdef KR_headers
  415. exdo(range, loopname, spec)
  416.     int range;
  417.     Namep loopname;
  418.     chainp spec;
  419. #else
  420. exdo(int range, Namep loopname, chainp spec)
  421. #endif
  422.             /* range = end label */
  423.             /* input spec must have at least 2 exprs */
  424. {
  425.     register expptr p;
  426.     register Namep np;
  427.     chainp cp;        /* loops over the fields in   spec */
  428.     register int i;
  429.     int dotype;        /* type of the index variable */
  430.     int incsign;        /* sign of the increment, if it's constant
  431.                    */
  432.     Addrp dovarp;        /* loop index variable */
  433.     expptr doinit;        /* constant or register for init param */
  434.     expptr par[3];        /* local specification parameters */
  435.  
  436.     expptr init, test, inc;    /* Expressions in the resulting FOR loop */
  437.  
  438.  
  439.     test = ENULL;
  440.  
  441.     pushctl(CTLDO);
  442.     dorange = ctlstack->dolabel = range;
  443.     ctlstack->loopname = loopname;
  444.  
  445. /* Declare the loop index */
  446.  
  447.     np = (Namep)spec->datap;
  448.     ctlstack->donamep = NULL;
  449.     if (!np) { /* do while */
  450.         ctlstack->dowhile = 1;
  451. #if 0
  452.         if (loopname) {
  453.             if (loopname->vtype == TYUNKNOWN) {
  454.                 loopname->vdcldone = 1;
  455.                 loopname->vclass = CLLABEL;
  456.                 loopname->vprocclass = PLABEL;
  457.                 loopname->vtype = TYLABEL;
  458.                 }
  459.             if (loopname->vtype == TYLABEL)
  460.                 if (loopname->vdovar)
  461.                     dclerr("already in use as a loop name",
  462.                         loopname);
  463.                 else
  464.                     loopname->vdovar = 1;
  465.             else
  466.                 dclerr("already declared; cannot be a loop name",
  467.                     loopname);
  468.             }
  469. #endif
  470.         putwhile((expptr)spec->nextp);
  471.         NOEXT("do while");
  472.         spec->nextp = 0;
  473.         frchain(&spec);
  474.         return;
  475.         }
  476.     if(np->vdovar)
  477.     {
  478.         errstr("nested loops with variable %s", np->fvarname);
  479.         ctlstack->donamep = NULL;
  480.         return;
  481.     }
  482.  
  483. /* Create a memory-resident version of the index variable */
  484.  
  485.     dovarp = mkplace(np);
  486.     if( ! ONEOF(dovarp->vtype, MSKINT|MSKREAL) )
  487.     {
  488.         err("bad type on do variable");
  489.         return;
  490.     }
  491.     ctlstack->donamep = np;
  492.  
  493.     np->vdovar = YES;
  494.  
  495. /* Now   dovarp   points to the index to be used within the loop,   dostgp
  496.    points to the one which may need to be stored */
  497.  
  498.     dotype = dovarp->vtype;
  499.  
  500. /* Count the input specifications and type-check each one independently;
  501.    this just eliminates non-numeric values from the specification */
  502.  
  503.     for(i=0 , cp = spec->nextp ; cp!=NULL && i<3 ; cp = cp->nextp)
  504.     {
  505.         p = par[i++] = fixtype((tagptr)cp->datap);
  506.         if( ! ONEOF(p->headblock.vtype, MSKINT|MSKREAL) )
  507.         {
  508.             err("bad type on DO parameter");
  509.             return;
  510.         }
  511.     }
  512.  
  513.     frchain(&spec);
  514.     switch(i)
  515.     {
  516.     case 0:
  517.     case 1:
  518.         err("too few DO parameters");
  519.         return;
  520.  
  521.     default:
  522.         err("too many DO parameters");
  523.         return;
  524.  
  525.     case 2:
  526.         DOINCR = (expptr) ICON(1);
  527.  
  528.     case 3:
  529.         break;
  530.     }
  531.  
  532.  
  533. /* Now all of the local specification fields are set, but their types are
  534.    not yet consistent */
  535.  
  536. /* Declare the loop initialization value, casting it properly and declaring a
  537.    register if need be */
  538.  
  539.     if (ISCONST (DOINIT) || !onetripflag)
  540. /* putx added 6-29-89 (mwm), not sure if fixtype is required, but I doubt it
  541.    since mkconv is called just before */
  542.         doinit = putx (mkconv (dotype, DOINIT));
  543.     else {
  544.         doinit = (expptr) mktmp(dotype, ENULL);
  545.         puteq (cpexpr (doinit), DOINIT);
  546.     } /* else */
  547.  
  548. /* Declare the loop ending value, casting it to the type of the index
  549.    variable */
  550.  
  551.     if( ISCONST(DOLIMIT) )
  552.         ctlstack->domax = mkconv(dotype, DOLIMIT);
  553.     else {
  554.         ctlstack->domax = (expptr) mktmp0(dotype, ENULL);
  555.         puteq (cpexpr (ctlstack -> domax), DOLIMIT);
  556.     } /* else */
  557.  
  558. /* Declare the loop increment value, casting it to the type of the index
  559.    variable */
  560.  
  561.     if( ISCONST(DOINCR) )
  562.     {
  563.         ctlstack->dostep = mkconv(dotype, DOINCR);
  564.         if( (incsign = conssgn(ctlstack->dostep)) == 0)
  565.             err("zero DO increment");
  566.         ctlstack->dostepsign = (incsign > 0 ? POSSTEP : NEGSTEP);
  567.     }
  568.     else
  569.     {
  570.         ctlstack->dostep = (expptr) mktmp0(dotype, ENULL);
  571.         ctlstack->dostepsign = VARSTEP;
  572.         puteq (cpexpr (ctlstack -> dostep), DOINCR);
  573.     }
  574.  
  575. /* All data is now properly typed and in the   ctlstack,   except for the
  576.    initial value.  Assignments of temps have been generated already */
  577.  
  578.     switch (ctlstack -> dostepsign) {
  579.         case VARSTEP:
  580.         test = mkexpr (OPQUEST, mkexpr (OPLT,
  581.             cpexpr (ctlstack -> dostep), ICON(0)),
  582.             mkexpr (OPCOLON,
  583.                 mkexpr (OPGE, cpexpr((expptr)dovarp),
  584.                     cpexpr (ctlstack -> domax)),
  585.                 mkexpr (OPLE, cpexpr((expptr)dovarp),
  586.                     cpexpr (ctlstack -> domax))));
  587.         break;
  588.         case POSSTEP:
  589.             test = mkexpr (OPLE, cpexpr((expptr)dovarp),
  590.             cpexpr (ctlstack -> domax));
  591.             break;
  592.         case NEGSTEP:
  593.             test = mkexpr (OPGE, cpexpr((expptr)dovarp),
  594.             cpexpr (ctlstack -> domax));
  595.             break;
  596.         default:
  597.             erri ("exdo:  bad dostepsign '%d'", ctlstack -> dostepsign);
  598.             break;
  599.     } /* switch (ctlstack -> dostepsign) */
  600.  
  601.     if (onetripflag)
  602.         test = mkexpr (OPOR, test,
  603.             mkexpr (OPEQ, cpexpr((expptr)dovarp), cpexpr (doinit)));
  604.     init = mkexpr (OPASSIGN, cpexpr((expptr)dovarp), doinit);
  605.     inc = mkexpr (OPPLUSEQ, (expptr)dovarp, cpexpr (ctlstack -> dostep));
  606.  
  607.     if (!onetripflag && ISCONST (ctlstack -> domax) && ISCONST (doinit)
  608.         && ctlstack -> dostepsign != VARSTEP) {
  609.         expptr tester;
  610.  
  611.         tester = mkexpr (OPMINUS, cpexpr (doinit),
  612.             cpexpr (ctlstack -> domax));
  613.         if (incsign == conssgn (tester))
  614.         warn ("DO range never executed");
  615.         frexpr (tester);
  616.     } /* if !onetripflag && */
  617.  
  618.     p1_for (init, test, inc);
  619. }
  620.  
  621.  void
  622. #ifdef KR_headers
  623. exenddo(np)
  624.     Namep np;
  625. #else
  626. exenddo(Namep np)
  627. #endif
  628. {
  629.     Namep np1;
  630.     int here;
  631.     struct Ctlframe *cf;
  632.  
  633.     if( ctlstack < ctls )
  634.         goto misplaced;
  635.     here = ctlstack->dolabel;
  636.     if (ctlstack->ctltype != CTLDO
  637.     || here >= 0 && (!thislabel || thislabel->labelno != here)) {
  638.  misplaced:
  639.         err("misplaced ENDDO");
  640.         return;
  641.         }
  642.     if (np != ctlstack->loopname) {
  643.         if (np1 = ctlstack->loopname)
  644.             errstr("expected \"enddo %s\"", np1->fvarname);
  645.         else
  646.             err("expected unnamed ENDDO");
  647.         for(cf = ctls; cf < ctlstack; cf++)
  648.             if (cf->ctltype == CTLDO && cf->loopname == np) {
  649.                 here = cf->dolabel;
  650.                 break;
  651.                 }
  652.         }
  653.     enddo(here);
  654.     }
  655.  
  656.  void
  657. #ifdef KR_headers
  658. enddo(here)
  659.     int here;
  660. #else
  661. enddo(int here)
  662. #endif
  663. {
  664.     register struct Ctlframe *q;
  665.     Namep np;            /* name of the current DO index */
  666.     Addrp ap;
  667.     register int i;
  668.     register expptr e;
  669.  
  670. /* Many DO's can end at the same statement, so keep looping over all
  671.    nested indicies */
  672.  
  673.     while(here == dorange)
  674.     {
  675.         if(np = ctlstack->donamep)
  676.             {
  677.             p1for_end ();
  678.  
  679. /* Now we're done with all of the tests, and the loop has terminated.
  680.    Store the index value back in long-term memory */
  681.  
  682.             if(ap = memversion(np))
  683.                 puteq((expptr)ap, (expptr)mkplace(np));
  684.             for(i = 0 ; i < 4 ; ++i)
  685.                 ctlstack->ctlabels[i] = 0;
  686.             deregister(ctlstack->donamep);
  687.             ctlstack->donamep->vdovar = NO;
  688.             /* ctlstack->dostep and ctlstack->domax can be zero */
  689.             /* with sufficiently bizarre (erroneous) syntax */
  690.             if (e = ctlstack->dostep)
  691.                 if (e->tag == TADDR && e->addrblock.istemp)
  692.                     frtemp((Addrp)e);
  693.                 else
  694.                     frexpr(e);
  695.             if (e = ctlstack->domax)
  696.                 if (e->tag == TADDR && e->addrblock.istemp)
  697.                     frtemp((Addrp)e);
  698.                 else
  699.                     frexpr(e);
  700.             }
  701.         else if (ctlstack->dowhile)
  702.             p1for_end ();
  703.  
  704. /* Set   dorange   to the closing label of the next most enclosing DO loop
  705.    */
  706.  
  707.         popctl();
  708.         poplab();
  709.         dorange = 0;
  710.         for(q = ctlstack ; q>=ctls ; --q)
  711.             if(q->ctltype == CTLDO)
  712.             {
  713.                 dorange = q->dolabel;
  714.                 break;
  715.             }
  716.     }
  717. }
  718.  
  719.  void
  720. #ifdef KR_headers
  721. exassign(vname, labelval)
  722.     register Namep vname;
  723.     struct Labelblock *labelval;
  724. #else
  725. exassign(register Namep vname, struct Labelblock *labelval)
  726. #endif
  727. {
  728.     Addrp p;
  729.     register Addrp q;
  730.     char *fs;
  731.     register chainp cp, cpprev;
  732.     register ftnint k, stno;
  733.  
  734.     p = mkplace(vname);
  735.     if( ! ONEOF(p->vtype, MSKINT|MSKADDR) ) {
  736.         err("noninteger assign variable");
  737.         return;
  738.         }
  739.  
  740.     /* If the label hasn't been defined, then we do things twice:
  741.      * once for an executable stmt label, once for a format
  742.      */
  743.  
  744.     /* code for executable label... */
  745.  
  746. /* Now store the assigned value in a list associated with this variable.
  747.    This will be used later to generate a switch() statement in the C output */
  748.  
  749.     fs = labelval->fmtstring;
  750.     if (!labelval->labdefined || !fs) {
  751.  
  752.         if (vname -> vis_assigned == 0) {
  753.             vname -> varxptr.assigned_values = CHNULL;
  754.             vname -> vis_assigned = 1;
  755.             }
  756.  
  757.         /* don't duplicate labels... */
  758.  
  759.         stno = labelval->stateno;
  760.         cpprev = 0;
  761.         for(k = 0, cp = vname->varxptr.assigned_values;
  762.                 cp; cpprev = cp, cp = cp->nextp, k++)
  763.             if ((ftnint)cp->datap == stno)
  764.                 break;
  765.         if (!cp) {
  766.             cp = mkchain((char *)stno, CHNULL);
  767.             if (cpprev)
  768.                 cpprev->nextp = cp;
  769.             else
  770.                 vname->varxptr.assigned_values = cp;
  771.             labelval->labused = 1;
  772.             }
  773.         putout(mkexpr(OPASSIGN, (expptr)p, mkintcon(k)));
  774.         }
  775.  
  776.     /* Code for FORMAT label... */
  777.  
  778.     if (!labelval->labdefined || fs) {
  779.  
  780.         labelval->fmtlabused = 1;
  781.         p = ALLOC(Addrblock);
  782.         p->tag = TADDR;
  783.         p->vtype = TYCHAR;
  784.         p->vstg = STGAUTO;
  785.         p->memoffset = ICON(0);
  786.         fmtname(vname, p);
  787.         q = ALLOC(Addrblock);
  788.         q->tag = TADDR;
  789.         q->vtype = TYCHAR;
  790.         q->vstg = STGAUTO;
  791.         q->ntempelt = 1;
  792.         q->memoffset = ICON(0);
  793.         q->uname_tag = UNAM_IDENT;
  794.         sprintf(q->user.ident, "fmt_%ld", labelval->stateno);
  795.         putout(mkexpr(OPASSIGN, (expptr)p, (expptr)q));
  796.         }
  797.  
  798. } /* exassign */
  799.  
  800.  
  801.  void
  802. #ifdef KR_headers
  803. exarif(expr, neglab, zerlab, poslab)
  804.     expptr expr;
  805.     struct Labelblock *neglab;
  806.     struct Labelblock *zerlab;
  807.     struct Labelblock *poslab;
  808. #else
  809. exarif(expptr expr, struct Labelblock *neglab, struct Labelblock *zerlab, struct Labelblock *poslab)
  810. #endif
  811. {
  812.     register int lm, lz, lp;
  813.  
  814.     lm = neglab->stateno;
  815.     lz = zerlab->stateno;
  816.     lp = poslab->stateno;
  817.     expr = fixtype(expr);
  818.  
  819.     if( ! ONEOF(expr->headblock.vtype, MSKINT|MSKREAL) )
  820.     {
  821.         err("invalid type of arithmetic if expression");
  822.         frexpr(expr);
  823.     }
  824.     else
  825.     {
  826.         if (lm == lz && lz == lp)
  827.             exgoto (neglab);
  828.         else if(lm == lz)
  829.             exar2(OPLE, expr, neglab, poslab);
  830.         else if(lm == lp)
  831.             exar2(OPNE, expr, neglab, zerlab);
  832.         else if(lz == lp)
  833.             exar2(OPGE, expr, zerlab, neglab);
  834.         else {
  835.             expptr t;
  836.  
  837.         if (!addressable (expr)) {
  838.         t = (expptr) mktmp(expr -> headblock.vtype, ENULL);
  839.         expr = mkexpr (OPASSIGN, cpexpr (t), expr);
  840.         } else
  841.         t = (expptr) cpexpr (expr);
  842.  
  843.         p1_if(putx(fixtype(mkexpr (OPLT, expr, ICON (0)))));
  844.         exgoto(neglab);
  845.         p1_elif (mkexpr (OPEQ, t, ICON (0)));
  846.         exgoto(zerlab);
  847.         p1_else ();
  848.         exgoto(poslab);
  849.         p1else_end ();
  850.         } /* else */
  851.     }
  852. }
  853.  
  854.  
  855.  
  856. /* exar2 -- Do arithmetic IF for only 2 distinct labels;   if !(e.op.0)
  857.    goto l2 else goto l1.  If this seems backwards, that's because it is,
  858.    in order to make the 1 pass algorithm work. */
  859.  
  860.  LOCAL void
  861. #ifdef KR_headers
  862. exar2(op, e, l1, l2)
  863.     int op;
  864.     expptr e;
  865.     struct Labelblock *l1;
  866.     struct Labelblock *l2;
  867. #else
  868. exar2(int op, expptr e, struct Labelblock *l1, struct Labelblock *l2)
  869. #endif
  870. {
  871.     expptr comp;
  872.  
  873.     comp = mkexpr (op, e, ICON (0));
  874.     p1_if(putx(fixtype(comp)));
  875.     exgoto(l1);
  876.     p1_else ();
  877.     exgoto(l2);
  878.     p1else_end ();
  879. }
  880.  
  881.  
  882. /* exreturn -- return the value in   p  from a SUBROUTINE call -- used to
  883.    implement the alternate return mechanism */
  884.  
  885.  void
  886. #ifdef KR_headers
  887. exreturn(p)
  888.     register expptr p;
  889. #else
  890. exreturn(register expptr p)
  891. #endif
  892. {
  893.     if(procclass != CLPROC)
  894.         warn("RETURN statement in main or block data");
  895.     if(p && (proctype!=TYSUBR || procclass!=CLPROC) )
  896.     {
  897.         err("alternate return in nonsubroutine");
  898.         p = 0;
  899.     }
  900.  
  901.     if (p || proctype == TYSUBR) {
  902.         if (p == ENULL) p = ICON (0);
  903.         p = mkconv (TYLONG, fixtype (p));
  904.         p1_subr_ret (p);
  905.     } /* if p || proctype == TYSUBR */
  906.     else
  907.         p1_subr_ret((expptr)retslot);
  908. }
  909.  
  910.  
  911.  void
  912. #ifdef KR_headers
  913. exasgoto(labvar)
  914.     Namep labvar;
  915. #else
  916. exasgoto(Namep labvar)
  917. #endif
  918. {
  919.     register Addrp p;
  920.  
  921.     p = mkplace(labvar);
  922.     if( ! ISINT(p->vtype) )
  923.         err("assigned goto variable must be integer");
  924.     else {
  925.         p1_asgoto (p);
  926.     } /* else */
  927. }
  928.